<template>
	<view class="">
		<common-title :title="titleContent" @clickLeft="backToUpPage"></common-title>
		<view class="message-list">
			<view class="message-list-item" v-for="(message, index) in messageList" :key="index">
				<view class="message-top">
					来自对象的工资换算申请
				</view>
				<view class="message-middle">
					<view class="message-wage">
						<view class="">{{message.wage}}</view>
						<view class="description">工资</view>
					</view>
					<image src="../../../static/images/mine/conversion.png" mode="aspectFill"/>
					<view class="message-coin">
						<view class="">{{message.coin}}</view>
						<view class="description">硬币</view>
					</view>
				</view>
				<view class="message-botton">
					<view class="request-user" v-if="userId === message.requestUser">
						<view v-if="message.status === 1">等待审批中<uni-icons type="spinner-cycle" size="20"></uni-icons></view>
					</view>
					<view class="response-user" v-else>
						<button class="refuse-button" @click="refuseButton(message.id)">驳回</button>
						<button class="confirm-button" @click="confirmButton(message.id)">同意</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, onMounted } from "vue";
	import { getDataFromStorage } from "../../../utils/commonUtils.js";
	import { wageConversionMessage, editWageConversionMessage } from "../../../utils/apiMine.js"
	//================================common-title=========================================
	//标题内容
	const titleContent = ref({
		left:'返回',
		midst:'工资换算消息'
	});
	
	//返回
	const backToUpPage = () => {
		uni.redirectTo({
			url:'/pages/mine/wage_coin/wage-conversion'
		})
	};
	//------------------------------------onMounted--------------------------------------------------
	const messageList = ref(null)
	const userId = ref(null);
	onMounted(() => {
		wageConversionMessage().then((res) => {
			messageList.value = res;
			// console.log(res)
		})
		
		getDataFromStorage('userId').then((res) => {
			userId.value = res;
		});
	})
	//-------------------------------------操作按钮--------------------------------------------------
	const refuseButton = (id) => {
		// console.log(id)
		let data = {
			'id':id,
			'status':3
		}
		editWageConversionMessage(data).then((res) => {
			uni.showToast({
				title:'已驳回',
				icon:'fail'
			})
			uni.redirectTo({
				url:'/pages/mine/wage_coin/wage-conversion-message'
			})
		})
	}
	const confirmButton = (id) =>{
		// console.log(id)
		let data = {
			'id':id,
			'status':2
		}
		editWageConversionMessage(data).then((res) => {
			uni.showToast({
				title:'已同意',
				icon:'success'
			})
			uni.redirectTo({
				url:'/pages/mine/wage_coin/wage-conversion-message'
			})
		})
	}
</script>

<style lang="scss" scoped>
	.message-list{
		height: calc(100vh - 44px); /* 设置高度使其在视口内 */
		overflow-y: auto; /* 允许垂直滚动 */
		display: flex;
		flex-direction: column;
		.message-list-item{
			width: 710rpx;
			height: 300rpx;
			margin: 20rpx;
			border-radius: 10px;
			background-color: bisque;
			.message-top{
				// background-color: aqua;
				margin: 5px;
				padding: 5px;
				border-bottom: 1px solid #ccc; /* 设置底部边框为 1px 的实线，颜色为浅灰色 */
			}
			.message-middle{
				margin: 5px;
				height: 120rpx;
				display: flex;
				align-items: center;
				justify-content: space-around;
				// background-color:saddlebrown;
				.message-wage, .message-coin{
					font-size: 20px;
					.description{
						margin-top: 10px;
						font-size: 16px;
					}
				}
				image{
					width: 30px;
					height: 30px;
				}
				padding: 5px;
				border-bottom: 1px solid #ccc; /* 设置底部边框为 1px 的实线，颜色为浅灰色 */
			}
			.message-botton{
				display: flex;
				align-items: center;
				justify-content: center;
				// background-color: beige;
				// height: 90rpx;
				.request-user{
					margin-bottom: 5px;
					display: flex;
					align-items: center;
					justify-content: center;
					// background-color: #ccc;
					height: 60rpx;
				}
				.response-user{
					width: 600rpx;
					margin-bottom: 5px;
					// background-color: #ccc;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.refuse-button{
						background-color: #FFCCFF;
						font-size: 16px;
					}
					.confirm-button{
						font-size: 16px;
						background-color: #87CEEB;
					}
				}
			}
		}
	}
</style>